<template "ui/head" />
<template "ui/iframe" />
<template "ui/background-none" />
<style>#LCONTENT{position:absolute;width:100%;height:100vh;top:0;padding:0}#Map{box-sizing:border-box;width:100%;height:calc(100vh - 50px);margin:50px 0 0 0;background:#FFFFFF;border:1px #e0e0e0 solid;border-radius:3px}#Body{position:absolute;box-sizing:border-box;z-index:99999;width:100%;top:0;left:0}#Info{margin-top:-1px}#Body button{position:absolute;right:0;top:0}#Config{display:block;position:absolute;bottom:0;right:0;padding:5px 10px;color:#FFFFFF;background:#F56C6C;z-index:999;cursor:pointer}.width-height{position:absolute;width:110px;top:0;right:92px}.width-height input{float:left;width:50%;box-sizing:border-box;margin:0;text-align:center;padding:0}.width-height input:last-child{margin-left:-1px}.width-height span{position:absolute;top:10px;right:48px;font-size:24px;line-height:20px}.tdt-infowindow-content{font-size:14px;word-break:break-all;white-space:pre-wrap;cursor:text}</style>
<div id="Body">
    <form class="layui-form" action="">
        <input id="Search" type="text" name="address" placeholder="请输入关键词，回车搜索" autocomplete="off" class="layui-input" />
        <button class="layui-btn" lay-submit>插入地图</button>
        <div class="width-height">
            <span>×</span>
            <input type="text" name="width" placeholder="长" required lay-verify="required" autocomplete="off" class="layui-input" value="100%" />
            <input type="text" name="height" placeholder="高" required lay-verify="required" autocomplete="off" class="layui-input" value="400" />
        </div>
    </form>
</div>
<div id="Map"></div>
<a id="Config" href="{{$_L['url']['own_form']}}api">修改Key</a>
<script type="text/javascript" onload>let initMap=function(){let map,marker,control,localsearch,infoW=false,info="公司名称：点击直接修改-XXXX科技有限公司<br>公司地址：XX省XX市XX路XX号工业园<br>联系电话：1888888888（微信同号）",keyword=document.getElementById("Search"),openInfo=function(){if(false===infoW){infoW=new T.InfoWindow(info,{autoPan:true,closeButton:false})}infoW.setContent(info);infoW.addEventListener("open",(function(e){$(e.target.uT).attr("contenteditable",true);$(".tdt-infowindow-content").on("input",(function(e){info=$(this).html();info=info.replace(/<\/div><div>/gi,"<br>");info=info.replace(/<div>/gi,"<br>");info=info.replace(/<\/div>/gi,"")}))}));infoW.addEventListener("close",(function(){$(".tdt-infowindow-content").off("input")}));marker.openInfoWindow(infoW)},addMarker=function(lnglat){if("clear"===lnglat){marker.removeEventListener("dragend");map.clearOverLays();return}else{lnglat=lnglat?lnglat:new T.LngLat(116.39126,39.90712)}marker=new T.Marker(lnglat);map.addOverLay(marker);marker.enableDragging();marker.addEventListener("dragend",(function(){openInfo()}));setTimeout((()=>{openInfo()}),500)},init=function(){map=new T.Map("Map");map.centerAndZoom(new T.LngLat(116.39126,39.90712),14);control=new T.Control.Zoom;control.setPosition(T_ANCHOR_BOTTOM_RIGHT);map.addControl(control);map.addControl(new T.Control.Scale);addMarker();localsearch=new T.LocalSearch(map,{pageCapacity:1,onSearchComplete:function(result){let data,lnglat;switch(parseInt(result.getResultType())){case 1:data=result.getPois();if(data&&data.length>0){lnglat=data[0].lonlat.split(",")}break;case 3:data=result.getArea();if(data){lnglat=data.lonlat.split(",")}break}if(lnglat){lnglat=new T.LngLat(lnglat[0],lnglat[1]);addMarker("clear");map.panTo(lnglat);addMarker(lnglat)}else{LCMS.util.notify({type:"error",content:"未找到相关地址，请重新输入关键词"})}}})};init();keyword.onkeydown=function(evt){evt=evt||event;if(13==evt.keyCode){if(!keyword.value){LCMS.util.notify({type:"error",content:"请输入地址进行搜索"});return false}localsearch.search(keyword.value,1);return false}};layui.form.on("submit",(function(form){let url,lnglat=map.getCenter(),zoom=map.getZoom(),point=marker.getLngLat();url=["../public/static/Map/tianditu/index.html?v=20250207#center="+lnglat.lng+","+lnglat.lat,"&zoom="+zoom,"&markers="+point.lng+","+point.lat+"&info="+encodeURIComponent(info)].join("");window.parent.postMessage({type:"lcms-editor-addmap",content:'<iframe src="'+url+'" frameborder="0" width="'+form.field.width+'" height="'+form.field.height+'"></iframe>'},"*");parent.layer.close(parent.layer.getFrameIndex(window.name));return false}))};LCMS.util.ajax({type:"GET",url:`${LCMS.url.own_form}api&action=get`,loading:true,success:res=>{if(1==res.code){LCMS.util.load({type:"js",src:`https://api.tianditu.gov.cn/api?v=4.0&tk=${res.data}`,onload:()=>{initMap()}})}else{LCMS.util.notify({type:"error",message:"缺少地图Key"})}}});</script>
<template "ui/foot" />